// @Date         2021-11-15
// @Author       Aaron Zhang
// @Description   日志
// @FileName      log.go

package contract

import (
	"context"
	"io"
	"time"
)

const (
	ProviderKeyLog = "fmk:log"
)

type LogLevel uint

const (
	LogLevelUnknown LogLevel = iota
	LogLevelPanic
	LogLevelFalter
	LogLevelError
	LogLevelWarn
	LogLevelInfo
	LogLevelDebug
	LogLevelTrace
)

type CtxFielder func(ctx context.Context) map[string]interface{}

// Formatter 日志格式化
type Formatter func(level LogLevel, t time.Time, msg string, fields map[string]interface{}) ([]byte, error)

type IContractLog interface {
	Panic(ctx context.Context, msg string, fields map[string]interface{})
	Fatal(ctx context.Context, msg string, fields map[string]interface{})
	Error(ctx context.Context, msg string, fields map[string]interface{})
	Warn (ctx context.Context, msg string, fields map[string]interface{})
	Info (ctx context.Context, msg string, fields map[string]interface{})
	Debug(ctx context.Context, msg string, fields map[string]interface{})
	Trace(ctx context.Context, msg string, fields map[string]interface{})

	SetLevel(level LogLevel)
	SetCtxFielder(handler CtxFielder)
	SetFormatter(formatter Formatter)
	SetOutput(writer ...io.Writer)
}
